package com.blog.cloud.service.bac.toLocal;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.select.Elements;

public class ExeMainService {
	
	
	
	
	
	
	public void downloadImgs_blog_sina(String url){
		
		Document document = PubUtil.getDocument(url);
		//System.out.println(document);
		
		
		List<String> titleUrlList = getTitleUrlList(document);
		
		if(titleUrlList!=null && titleUrlList.size()>0){
			for (String titUrl : titleUrlList) {
				Document document2 = PubUtil.getDocument(titUrl);
				Elements ele = document2.getElementsByAttributeValue("id", "sina_keyword_ad_area2");
				for (Element element : ele) {
					
					Elements children = element.children();
					
					for (Element element2 : children) {
						Elements elementsByTag = element2.getElementsByTag("img");
						for (Element element3 : elementsByTag) {
							
							System.out.println(element3);
							
						}
					}
					
					
					
				}
				
				
				break;
				
			}
		}
	}





	public List<String> getTitleUrlList(Document document) {
		
		List<String> urlList = new ArrayList<String>();
		Elements elements = document.getElementsByAttributeValue("class", "articleCell SG_j_linedot1");
		for (Element element : elements) {
			Element child = element.child(0).child(1).child(0);
			String attr = child.attr("href");
			urlList.add(attr);
		}
		return urlList;
	}
	
	
	
	
	

	
	
	
	public static void main(String[] args) {
		String url = "http://blog.sina.com.cn/s/articlelist_3820469585_0_1.html";
		new ExeMainService().downloadImgs_blog_sina(url);
	}
}
